package com.java2007.zhangyu.restaurant.controller.backend;

import com.java2007.zhangyu.restaurant.constant.ServletConstant;
import com.java2007.zhangyu.restaurant.controller.BaseServlet;
import com.java2007.zhangyu.restaurant.pojo.Admin;
import com.java2007.zhangyu.restaurant.pojo.DinnerTable;
import com.java2007.zhangyu.restaurant.pojo.Order;
import com.java2007.zhangyu.restaurant.pojo.OrderDetail;
import com.java2007.zhangyu.restaurant.service.AdminService;
import com.java2007.zhangyu.restaurant.service.OrderDetailService;
import com.java2007.zhangyu.restaurant.service.OrderService;
import com.java2007.zhangyu.restaurant.service.TableService;
import com.java2007.zhangyu.restaurant.service.impl.AdminServiceImpl;
import com.java2007.zhangyu.restaurant.service.impl.OrderDetailServiceImpl;
import com.java2007.zhangyu.restaurant.service.impl.OrderServiceImpl;
import com.java2007.zhangyu.restaurant.service.impl.TableServiceImpl;
import com.sun.org.apache.xpath.internal.operations.Or;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单控制器
 * @author zy
 * @Version
 * @date 2021/01/26
 */
@WebServlet("/backendOrder")
public class OrderController extends BaseServlet {

    private OrderService orderService = new OrderServiceImpl();
    private TableService tableService = new TableServiceImpl();
    private OrderDetailService orderDetailService = new OrderDetailServiceImpl();

    /**
     * 查询所有订单
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public String queryAllOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //订单查询
        List<Order> orders = orderService.queryAllOrder();
        //将查询结果翻入request域中
        request.setAttribute("orders",orders);

        //餐桌查询
        List<DinnerTable> tables = tableService.queryAll();
        //将查询结果翻入request域中
        request.setAttribute("tables",tables);

        return ServletConstant.PRE_FORWARD+"/backend/detail/order/order-list.jsp";
    }

    /**
     * 查询所有订单的详情
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public String queryAllOrderDetail(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //获取请求参数
        String oIdStr = request.getParameter("oId");

        Long oId = Long.valueOf(oIdStr);

        //根据订单id查询顶啊孤单详情
        List<OrderDetail> orderDetails = orderDetailService.queryByOrderId(oId);
        //将查询结果翻入request域中
        request.setAttribute("orderDetails",orderDetails);

        //餐桌查询
        List<DinnerTable> tables = tableService.queryAll();

        request.setAttribute("tables",tables);
        return ServletConstant.PRE_FORWARD+"/backend/detail/order/order-detail.jsp";
    }
}
